// Depends on tencentcloud-sdk-nodejs version 4.0.3 or higher
const tencentcloud = require("tencentcloud-sdk-nodejs");

module.exports = {
    sendSMS(tel, code) {
        const SmsClient = tencentcloud.sms.v20210111.Client;
        const clientConfig = {
            credential: {
                secretId: "AKIDHNEqDVXP7ctxoRqzvfCWdXHo7FAtPktq",
                secretKey: "mKdhW5PaVHqCLH3e2DD0ax73oMkxxkKk",
            },
            region: "ap-nanjing",
            profile: {
                httpProfile: {
                    endpoint: "sms.tencentcloudapi.com",
                },
            },
        };
        const client = new SmsClient(clientConfig);
        const params = {
            "PhoneNumberSet": [
                "+86" + tel
            ],
            "SmsSdkAppId": "1400695029",
            "SignName": "菏泽祥膳百货",
            "TemplateId": "1444772",
            "TemplateParamSet": [
                "" + code,
                "2"
            ]
        };
        return client.SendSms(params);
    },
    randomnumber(n) {
        let str = "";
        for (let i = 0; i < n; i++) {
            str += Math.round(Math.random() * 9)
        }
        return str;
    }
}